import { Button, Checkbox, Form, Input, Card, message } from 'antd'
import './index.scss'
import { useStore } from '@/store'
import { useNavigate } from 'react-router-dom'
function Login () {
  const { loginStore } = useStore()
  const navigate = useNavigate()
  async function onFinish (e) {
    console.log(e)
    try {
      await loginStore.getToken({
        mobile: e.username,
        code: e.password
      })
      navigate("/", { replace: true })
      message.success('登陆成功')
    } catch (e) {
      message.error(e.response?.data?.message || '登录失败')
    }



  }
  return (
    <div className="login">
      <Card className="login-container">
        <Form
          onFinish={onFinish}>
          <Form.Item
            name="username"
            rules={[{
              required: true,
              message: '账号不能为空!'
            }]}
          >
            <Input size="large" placeholder="请输入账号" />
          </Form.Item>
          <Form.Item
            name="password"
            rules={[{
              required: true,
              message: '密码不能为空!'
            }]}>
            <Input size="large" placeholder="请输入密码" />
          </Form.Item>
          <Form.Item name='remenber' valuePropName="checked">
            <Checkbox className="login-checkbox-label" >
              我已阅读并同意「用户协议」和「隐私条款」
            </Checkbox>
          </Form.Item>
          <Form.Item
            rules={[{
              required: true
            }]}
          >
            <Button type="primary" htmlType="submit" size="large" block>
              登录
            </Button>
          </Form.Item>
        </Form>
      </Card>
    </div>

  )
}
export default Login
